<?php
declare(strict_types = 1);

namespace app\common\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class User extends Model
{
    //
    public function getUserByPhoneNumber($phoneNumber)
    {
        if (empty($phoneNumber)) {
            return false;
        }

        $where = [
            'phone_number' => $phoneNumber
        ];

        $result = $this->where($where)->find();
        return $result;
    }

    // 修改数据
    public function updateUser($id, $data)
    {
        $where = [
            'id' => $id
        ];

        $user = $this->where($where)->find();

        $res = $user->save($data);
        return $res;
    }

    // 通过id获取用户
    public function getUserById($id)
    {
        if (empty($id)) {
            return false;
        }

        $where = [
            'id' => $id
        ];

        $res = $this->where($where)->find();
        return $res;
    }

    // 通过用户名获取用户数据
    public function getUserByUserName($username)
    {
        if (empty($username)) {
            return false;
        }
        $where = [
            'username' => $username
        ];
        
        return $this->where($where)->find();
    }
}
